package com.vm.osm.business.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.vm.osm.business.dao.KnowledgeBaseMapper;
import com.vm.osm.business.dto.rsp.knowledgeBase.RspKnowledgeBase;
import com.vm.osm.business.dto.rsp.knowledgeBase.RspKnowledgePage;
import com.vm.osm.business.entity.KnowledgeBase;
import com.vm.osm.business.service.IKnowledgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by chenzui on 2018/1/23.
 */
@Service
public class KnowledgeServiceImpl implements IKnowledgeService {

    @Autowired
    private KnowledgeBaseMapper knowledgeMapper;

    @Override
    public int deleteByPrimaryKey(String id) {
        return knowledgeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(KnowledgeBase record) {
        return knowledgeMapper.insert(record);
    }

    @Override
    public int insertSelective(KnowledgeBase record) {
        return knowledgeMapper.insertSelective(record);
    }

    @Override
    public KnowledgeBase selectByPrimaryKey(String id) {
        return knowledgeMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(KnowledgeBase record) {
        return knowledgeMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(KnowledgeBase record) {
        return knowledgeMapper.updateByPrimaryKey(record);
    }

    @Override
    public RspKnowledgePage findPage(Integer pageNum, Integer pageSize, String typeId, String search) {
        RspKnowledgePage rspKnowledgePage = new RspKnowledgePage();
        Page page = PageHelper.startPage(pageNum,pageSize,true);
        List<RspKnowledgeBase> dataList = knowledgeMapper.findPage(typeId,search);
        rspKnowledgePage.setData_list(dataList);
        rspKnowledgePage.setTotal_num(page.getTotal());
        rspKnowledgePage.setPage_num(page.getPageNum());
        rspKnowledgePage.setPage_size(page.getPageSize());
        return rspKnowledgePage;
    }
}
